package com.vterm4aKafka.controller;

import com.vterm4aKafka.domain.FourAInfoReq;
import com.vterm4aKafka.service.FourAInfoSearchService;
import com.vterm4aKafka.utils.JsonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @ program: elasticSearch_springBoot_study
 * @ description:
 * @ author: Mr.Zhongsf
 * @ create: 2021-03-18 09:57
 **/
@RestController
@RequestMapping("/vterm")
public class FourAInfoController {
    @Resource
    private FourAInfoSearchService fourAInfoSearch;

    @PostMapping("/fourAInfoSearch")
    public JsonResponse vtermDefaultInfo(@RequestBody @Valid FourAInfoReq fourAInfoReq, BindingResult bindingResult) {
        System.out.println("controller开始执行了");

        if (bindingResult != null && bindingResult.hasErrors()) {
            String messages = bindingResult.getAllErrors()
                    .stream()
                    .map(ObjectError::getDefaultMessage)
                    .reduce((m1, m2) -> m1 + "；" + m2)
                    .orElse("参数输入有误");
            return JsonResponse.responseFail2(messages);
        }

        return JsonResponse.respSuccess(fourAInfoSearch.selectFourAInfo(fourAInfoReq));
    }


}
